home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / tcoop.arc / TCOOP2.ARC / GBUTNTST.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-26  |  2.9 KB  |  98 lines

  1. // gbutntst.cpp: Tests the graphics buttons.
  2. // Press on Exit button to quit or type ALT-X key combination. 
  3.  
  4. #include <string.h>
  5. #include "grphscrn.h"
  6. #include "gbutton.h"
  7.  
  8. void ChangeTextAction(Wso *Src, MsgPkt &)
  9. // Changes the text on a button 
  10. {
  11.   TextButton *Tb = (TextButton *)Src;
  12.   if (!strcmp(Tb->Str, "Press"))
  13.     strcpy(Tb->Str, "Press Again");
  14.     else strcpy(Tb->Str, "Press");
  15.   Tb->ChangeText(Tb->Str, Tb->Font);
  16. }
  17.  
  18. // ---------- Some routines to draw icon ----------- 
  19.  
  20. void DrawRightArrow(Wso *Src)
  21. // Draws a right arrow icon 
  22. {
  23.   int MidX, MidY;
  24.   Mouse.Hide();
  25.   MidX = Src->Panel->Interior->Xul + Src->Panel->Interior->Wd / 2;
  26.   MidY = Src->Panel->Interior->Yul + Src->Panel->Interior->Ht / 2;
  27.   setcolor(ForeGround(Src->Panel->Colors.Wc));
  28.   moveto(MidX+6,MidY+6);
  29.   lineto(MidX+6,MidY-6);
  30.   lineto(MidX-2,MidY-6);
  31.   lineto(MidX-2,MidY-10);
  32.   lineto(MidX-8,MidY);
  33.   lineto(MidX-2,MidY+10);
  34.   lineto(MidX-2,MidY+6);
  35.   lineto(MidX+6,MidY+6);
  36.   setfillstyle(SOLID_FILL,ForeGround(Src->Panel->Colors.Wc));
  37.   floodfill(MidX,MidY,ForeGround(Src->Panel->Colors.Wc));
  38.   Mouse.Show();
  39. }
  40.  
  41. void DrawLeftArrow(Wso *Src)
  42. // Draws a left arrow icon 
  43. {
  44.   int MidX, MidY;
  45.   Mouse.Hide();
  46.   MidX = Src->Panel->Interior->Xul + Src->Panel->Interior->Wd / 2;
  47.   MidY = Src->Panel->Interior->Yul + Src->Panel->Interior->Ht / 2;
  48.   setcolor(ForeGround(Src->Panel->Colors.Wc));
  49.   moveto(MidX-6,MidY+6);
  50.   lineto(MidX-6,MidY-6);
  51.   lineto(MidX+2,MidY-6);
  52.   lineto(MidX+2,MidY-10);
  53.   lineto(MidX+8,MidY);
  54.   lineto(MidX+2,MidY+10);
  55.   lineto(MidX+2,MidY+6);
  56.   lineto(MidX-6,MidY+6);
  57.   setfillstyle(SOLID_FILL,ForeGround(Src->Panel->Colors.Wc));
  58.   floodfill(MidX,MidY,ForeGround(Src->Panel->Colors.Wc));
  59.   Mouse.Show();
  60. }
  61.  
  62. main()
  63. {
  64.   TextButton *ExitButton;
  65.   IconButton *LeftButton;
  66.   IconButton *RightButton;
  67.   TextButton *ChangeButton;
  68.   TextButton *CloseButton;
  69.   int Gd, Gm;
  70.  
  71.   Gd = DETECT;
  72.   Setup(MouseOptional, Gd, Gm, "\\tcpp\\bgi", SANS_SERIF_FONT);
  73.   FullScrn->Panel->Clear(' ', 0x70);
  74.   LeftButton = new IconButton(DrawLeftArrow, Relief+3,
  75.      Swappable, GrphColors, NoOp);
  76.   RightButton = new IconButton(DrawRightArrow, Relief+3,
  77.      Swappable, GrphColors, NoOp);
  78.   ExitButton = new TextButton("Exit", "roman", Relief+3,
  79.      Swappable, GrphColors, ExitAction);
  80.   ChangeButton = new TextButton("Press", "roman", Relief+3,
  81.      Swappable+OutlineMove, GrphColors, ChangeTextAction);
  82.   CloseButton = new TextButton("Close Me", "roman", Relief+3,
  83.      Swappable+OutlineMove+Closeable, GrphColors, NoOp);
  84.  
  85.   LeftButton->Open(FullScrn, 20, 20);   // Buttons default to 25 by 25 
  86.   RightButton->Open(FullScrn, 70, 20);  // pixels in size 
  87.   ExitButton->SetSize(25, 40);
  88.   ExitButton->Open(FullScrn, 200, 20);
  89.   ChangeButton->SetSize(100, 50);
  90.   ChangeButton->Open(FullScrn, 150, 125);
  91.   CloseButton->SetSize(75, 25);
  92.   CloseButton->Open(FullScrn, 250, 250);
  93.   MainEventLoop();
  94.   CleanUp();
  95. }
  96.  
  97.  
  98.